package com.test.daily.leetcode.y2022.m07.day0704.v02;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Tom on 2022/7/4
 */
public class Solution {
    public static void main(String[] args) {
        int[] arr= new int[]{4,2,1,3};
        new Solution().minimumAbsDifference(arr);
    }
    public List<List<Integer>> minimumAbsDifference(int[] arr) {
        Arrays.sort(arr);
        int N = arr.length;
        int minAbsDiff = Integer.MAX_VALUE;
        List<List<Integer>> ans = new ArrayList<>();
        for (int i = 0; i < N - 1; i++) {
            int delta = arr[i+1] - arr[i];
            if(delta < minAbsDiff) {
                minAbsDiff = delta;
                ans.clear();
            }
            if(delta == minAbsDiff){
                ArrayList<Integer> list = new ArrayList<>();
                list.add(arr[i]);
                list.add(arr[i+1]);
                ans.add(list);
            }
        }
        return ans;
    }
}
